import java.util.Arrays;

public class L27R {

    public static void main(String[] args) {
        int[] nums = {0, 1, 2, 2, 3, 0, 4, 2};
        int val = 2;

        int i = new Solution().removeElement(nums, val);
        System.out.println(Arrays.toString(nums));
        System.out.println(i);


    }

    static class Solution {
        public int removeElement(int[] nums, int val) {
            int slow = 0;
            for (int fast = 0; fast < nums.length; fast++) {
                if (nums[fast] != val) {
                    nums[slow] = nums[fast];
                    slow++;
                }
            }
            return slow;
        }
    }
}
